import { Component, OnInit } from '@angular/core';
import { ApiService } from '../../../../providers/ApiPro.service';
import { parts } from '../HuoSettmp.model';


@Component({
  selector: 'app-SetUser',
  templateUrl: './SetUser.component.html',
  styleUrls: ['./SetUser.component.scss']
})
export class SetUserComponent implements OnInit {
  data = [];
  public _total = 0;
  public pageIndex = 1;
  public parts: parts = new parts();
  public optionPostion: any;
  constructor(
    public apiService: ApiService,
  ) { }

  ngOnInit() {
        this.loadAll();
        this.getPostion();
  }

  loadAll(){
    let url = "findusers";
    if(!this.parts.userName){
      delete this.parts.userName;    
    }
    if(!this.parts.mobile){
      delete this.parts.mobile;    
    }
    if(!this.parts.positionName){
      delete this.parts.positionName;
    }
    console.log(this.parts);
    this.apiService.get(url,this.parts)
      .then(res =>{
        this._total = res.totalCount;
        this.data = res.result;
      })
  }

  getPostion(){
    let url = "findallpositions";
    this.apiService.get(url)
      .then(res =>{
        this.optionPostion = res.result;
      })    
  }

  resetIndex(e) {
        console.log(e);
        this.parts.setPage(e);
        this.loadAll();
  }

}
